home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Actions / ActionApp2U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-05-16  |  1.3 KB  |  59 lines

  1. unit ActionApp2U;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ActnList, ImgList, ComCtrls, ToolWin, Menus, Buttons;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     edtEntry: TEdit;
  12.     Label1: TLabel;
  13.     lstEntries: TListBox;
  14.     btnAddString: TBitBtn;
  15.     ActionList: TActionList;
  16.     ImageList: TImageList;
  17.     actAddString: TAction;
  18.     MainMenu: TMainMenu;
  19.     File1: TMenuItem;
  20.     AddString1: TMenuItem;
  21.     N1: TMenuItem;
  22.     Exit1: TMenuItem;
  23.     PopupMenu: TPopupMenu;
  24.     AddString2: TMenuItem;
  25.     ToolBar1: TToolBar;
  26.     ToolButton1: TToolButton;
  27.     procedure actAddStringExecute(Sender: TObject);
  28.     procedure actAddStringUpdate(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TForm1.actAddStringExecute(Sender: TObject);
  43. begin
  44.   lstEntries.Items.Add( Trim( edtEntry.Text ) );
  45.   //Give focus back to edit
  46.   edtEntry.SetFocus;
  47.   //Highlight edit's contents so it can be replaced by overtyping
  48.   edtEntry.SelectAll;
  49. end;
  50.  
  51. procedure TForm1.actAddStringUpdate(Sender: TObject);
  52. begin
  53.   (Sender as TAction).Enabled :=
  54.     ( Length( Trim( edtEntry.Text ) ) > 0 ) and
  55.     ( lstEntries.Items.IndexOf( Trim( edtEntry.Text ) ) = -1 )
  56. end;
  57.  
  58. end.
  59.